import pickle
import pandas as pd

#计算一下各因子之间的相关系数
#但是最后没用到hhh
def calculate_corr(data):
    stocks = {}
    for day in data:
        df = data[day]
        for index,row in df.iterrows():
            if index not in stocks:
                stocks[index] = {}
            row = dict(list(row.items()))
            for k in row:
                if k not in stocks[index]:
                    stocks[index][k] = []
                stocks[index][k].append(row[k])
    stock_corrs = {}
    for s in stocks:
        stock_corrs[s] = {}
    for s in stocks:
        df = pd.DataFrame(stocks[s])
        corr = df.corr() 
        stock_corrs[s] = corr
    return stock_corrs

if __name__=='__main__':
    with open('data.pkl','rb') as f:
        data = pickle.load(f)
    calculate_corr(data)